import { b2CircleShape, b2EdgeShape, b2PolygonShape, b2Vec2 } from "@box2d/core";
import { Behaviour } from "./Behaviour";
import { Serialized } from "./Serialized";

export class CircleCollider extends Behaviour {

    _radius: number = 0;

    shape: b2CircleShape;

    @Serialized('numberInput')
    get radius() {
        return this._radius;
    }

    set radius(value: number) {
        this._radius = value;
        if (this.shape) {
            this.shape.m_radius = this._radius;
        }

    }
}

export class EdgeCollider extends Behaviour {

    private _startX: number = 0;
    private _startY: number = 0;
    private _endX: number = 0;
    private _endY: number = 0;

    shape: b2EdgeShape;


    @Serialized('numberInput')
    get startX() {
        return this._startX;
    }

    set startX(value: number) {
        this._startX = value;
        this.update();
    }

    @Serialized('numberInput')
    get startY() {
        return this._startY;
    }

    set startY(value: number) {
        this._startY = value;
        this.update();
    }

    @Serialized('numberInput')
    get endX() {
        return this._endX;
    }

    set endX(value: number) {
        this._endX = value;
        this.update();
    }

    @Serialized('numberInput')
    get endY() {
        return this._endY;
    }

    set endY(value: number) {
        this._endY = value;
        this.update();
    }

    private update() {
        if (this.shape) {
            this.shape.SetTwoSided({ x: this._startY, y: this.startY }, { x: this.endX, y: this.endY })
        }
    }
}

export class BoxCollider extends Behaviour {

    shape: b2PolygonShape;

    _edge: number = 0;

    @Serialized('numberInput')
    get edge() {
        return this._edge
    }

    set edge(value: number) {
        this._edge = value;
        this.update();
    }

    update() {
        if (this.shape) {
            this.shape.SetAsBox(this.edge / 2, this.edge / 2, new b2Vec2(0, 0), 0);
        }
    }
}